"""import pygame
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
qipan=[[0,0,0],[0,0,0],[0,0,0]]
n=0
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
jing()
shua()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=n%2+1
                        n+=1
                        print(n%2+1)
                    else:
                        print("NO")
                    drawing(qipan)
""""""
import pygame,time
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
def red():
    print('red wing')
    time.sleep(2)
    pygame.quit()
def hei2():
    print('black wing')
    time.sleep(2)
    pygame.quit()
def wing(x):
    if x[0][0]==x[0][1]==x[0][2]==1:
        red()
    elif x[0][0]==x[0][1]==x[0][2]==2:
        hei2()
    elif x[1][0]==x[1][1]==x[1][2]==1:
        red()
    elif x[1][0]==x[1][1]==x[1][2]==2:
        hei2()
    elif x[2][0]==x[2][1]==x[2][2]==1:
        red()
        print(3)
    elif x[2][0]==x[2][1]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][0]==x[2][0]==1:
        red()
    elif x[0][0]==x[1][0]==x[2][0]==2:
        hei2()
    elif x[0][1]==x[1][1]==x[2][1]==1:
        red()
    elif x[0][1]==x[1][1]==x[2][1]==2:
        hei2()
    elif x[0][2]==x[1][2]==x[2][2]==1:
        red()
    elif x[0][2]==x[1][2]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][1]==x[2][2]==1:
        red()
    elif x[0][0]==x[1][1]==x[2][2]==2:
        hei2()
    elif x[2][0]==x[1][1]==x[0][2]==1:
        red()
    elif x[2][0]==x[1][1]==x[0][2]==2:
        hei2()
    elif x[0][0]!=0 and x[0][1]!=0 and x[0][2]!=0 and x[1][0]!=0 and x[1][1]!=0 and x[1][2]!=0 and x[2][0]!=0 and x[2][1]!=0 and x[2][2]!=0:
        print("平局")
        time.sleep(2)
        pygame.quit()
qipan=[[0,0,0],[0,0,0],[0,0,0]]
n=0
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
jing()
shua()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=n%2+1
                        n+=1
                        #print(n%2+1)
                    else:
                        print("NO")
                    drawing(qipan)
                    #print(qipan)
                    wing(qipan)


""""""
import pygame,time,random
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
def red():
    print('red wing')
    time.sleep(2)
    pygame.quit()
def hei2():
    print('black wing')
    time.sleep(2)
    pygame.quit()
def wing(x):
    if x[0][0]==x[0][1]==x[0][2]==1:
        red()
    elif x[0][0]==x[0][1]==x[0][2]==2:
        hei2()
    elif x[1][0]==x[1][1]==x[1][2]==1:
        red()
    elif x[1][0]==x[1][1]==x[1][2]==2:
        hei2()
    elif x[2][0]==x[2][1]==x[2][2]==1:
        red()
        print(3)
    elif x[2][0]==x[2][1]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][0]==x[2][0]==1:
        red()
    elif x[0][0]==x[1][0]==x[2][0]==2:
        hei2()
    elif x[0][1]==x[1][1]==x[2][1]==1:
        red()
    elif x[0][1]==x[1][1]==x[2][1]==2:
        hei2()
    elif x[0][2]==x[1][2]==x[2][2]==1:
        red()
    elif x[0][2]==x[1][2]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][1]==x[2][2]==1:
        red()
    elif x[0][0]==x[1][1]==x[2][2]==2:
        hei2()
    elif x[2][0]==x[1][1]==x[0][2]==1:
        red()
    elif x[2][0]==x[1][1]==x[0][2]==2:
        hei2()
    elif x[0][0]!=0 and x[0][1]!=0 and x[0][2]!=0 and x[1][0]!=0 and x[1][1]!=0 and x[1][2]!=0 and x[2][0]!=0 and x[2][1]!=0 and x[2][2]!=0:
        print("平局")
        time.sleep(2)
        pygame.quit()
def qi(x,a,b):
    if x[a][b]!=0:
        m=0
        while m==0:
            c=random.randint(0,2)
            d=random.randint(0,2)
            if x[c][d]!=0:
                pass
            if x[c][d]==0:
                x[c][d]+=2
                m+=1
            print(12345)
    if x[a][b]==0:
            x[a][b]+=2
def player2(x):
    if x[0][0]==x[0][1]==1:
        qi(x,0,2)
    elif x[0][0]==x[0][2]==1:
        qi(x,0,1)
    elif x[0][1]==x[0][2]==1:
        qi(x,0,0)
    elif x[1][0]==x[1][1]==1:
         qi(x,1,2)
    elif x[1][0]==x[1][2]==1:
        qi(x,1,1)
    elif x[1][1]==x[1][2]==1:
        qi(x,1,0)
    elif x[2][0]==x[2][1]==1:
        qi(x,2,2)
    elif x[2][0]==x[2][2]==1:
        qi(x,2,1)
    elif x[2][1]==x[2][2]==1:
        qi(x,2,0)

    elif x[0][0]==x[1][0]==1:
        qi(x,2,0)
    elif x[0][0]==x[2][0]==1:
        qi(x,1,0)
    elif x[1][0]==x[2][0]==1:
        qi(x,0,0)
    elif x[0][1]==x[1][1]==1:
         qi(x,2,1)
    elif x[0][1]==x[2][1]==1:
        qi(x,1,1)
    elif x[1][1]==x[2][1]==1:
        qi(x,0,1)
    elif x[0][2]==x[1][2]==1:
        qi(x,2,2)
    elif x[0][2]==x[2][2]==1:
        qi(x,1,2)
    elif x[1][2]==x[2][2]==1:
        qi(x,0,2)

    elif x[0][0]==x[1][1]==1:
        qi(x,2,2)
        #print(1)
    elif x[0][0]==x[2][2]==1:
        qi(x,1,1)
        #print(2)
    elif x[1][1]==x[2][2]==1:
        qi(x,0,0)
    #    print(3)
    elif x[2][0]==x[1][1]==1:
        qi(x,0,2)
    #    print(4)
    elif x[0][2]==x[1][1]==1:
        qi(x,2,0)
    #    print(5)
    elif x[0][2]==x[2][0]==1:
        qi(x,1,1)
        #print(6)

    else:
        m=0
        while m==0:
            a=random.randint(0,2)
            b=random.randint(0,2)
            if x[a][b]!=0:
                pass
            if x[a][b]==0:
                x[a][b]+=2
                m+=1
qipan=[[0,0,0],[0,0,0],[0,0,0]]
n=0
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
jing()
shua()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=n%2+1
                        n+=1
                        drawing(qipan)
                        print(qipan)
                        wing(qipan)

                        if n<9:
                            player2(qipan)
                            n+=1
                    else:
                        print("NO")
                    drawing(qipan)
                    print(qipan)
                    wing(qipan)
                

"""

import pygame,time,random
def jingziqi():
    def shua():
        pygame.display.flip()

    def jing():
        pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
        pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
        pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
        pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
        shua()

    def hong(a,b):
        pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
    def hei(a,b):
        pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
    def drawing(qipan):
        jing()
        for i in range(0,3):
            for j in range(0,3):
                if qipan[i][j]==0:
                    pass
                if qipan[i][j]==1:
                    hong(i,j)
                if qipan[i][j]==2:
                    hei(i,j)
        shua()

    def red():
        print('red wing')
        time.sleep(2)
    def hei2():
        print('black wing')
        time.sleep(2)
        pygame.quit()
    def wing(x):
        if x[0][0]==x[0][1]==x[0][2]==1:
            red()
        elif x[0][0]==x[0][1]==x[0][2]==2:
            hei2()
        elif x[1][0]==x[1][1]==x[1][2]==1:
            red()
        elif x[1][0]==x[1][1]==x[1][2]==2:
            hei2()
        elif x[2][0]==x[2][1]==x[2][2]==1:
            red()
            print(3)
        elif x[2][0]==x[2][1]==x[2][2]==2:
            hei2()
        elif x[0][0]==x[1][0]==x[2][0]==1:
            red()
        elif x[0][0]==x[1][0]==x[2][0]==2:
            hei2()
        elif x[0][1]==x[1][1]==x[2][1]==1:
            red()
        elif x[0][1]==x[1][1]==x[2][1]==2:
            hei2()
        elif x[0][2]==x[1][2]==x[2][2]==1:
            red()
        elif x[0][2]==x[1][2]==x[2][2]==2:
            hei2()
        elif x[0][0]==x[1][1]==x[2][2]==1:
            red()
        elif x[0][0]==x[1][1]==x[2][2]==2:
            hei2()
        elif x[2][0]==x[1][1]==x[0][2]==1:
            red()
        elif x[2][0]==x[1][1]==x[0][2]==2:
            hei2()
        elif x[0][0]!=0 and x[0][1]!=0 and x[0][2]!=0 and x[1][0]!=0 and x[1][1]!=0 and x[1][2]!=0 and x[2][0]!=0 and x[2][1]!=0 and x[2][2]!=0:
            print("平局")
            time.sleep(2)

    def qi(x,a,b):
        if x[a][b]!=0:
            m=0
            while m==0:
                c=random.randint(0,2)
                d=random.randint(0,2)
                if x[c][d]!=0:
                    pass
                if x[c][d]==0:
                    x[c][d]+=2
                    m+=1
                print(12345)
        if x[a][b]==0:
                x[a][b]+=2
    def player2(x):
        if x[0][0]==x[0][1]==1:
            qi(x,0,2)
        elif x[0][0]==x[0][2]==1:
            qi(x,0,1)
        elif x[0][1]==x[0][2]==1:
            qi(x,0,0)
        elif x[1][0]==x[1][1]==1:
             qi(x,1,2)
        elif x[1][0]==x[1][2]==1:
            qi(x,1,1)
        elif x[1][1]==x[1][2]==1:
            qi(x,1,0)
        elif x[2][0]==x[2][1]==1:
            qi(x,2,2)
        elif x[2][0]==x[2][2]==1:
            qi(x,2,1)
        elif x[2][1]==x[2][2]==1:
            qi(x,2,0)

        elif x[0][0]==x[1][0]==1:
            qi(x,2,0)
        elif x[0][0]==x[2][0]==1:
            qi(x,1,0)
        elif x[1][0]==x[2][0]==1:
            qi(x,0,0)
        elif x[0][1]==x[1][1]==1:
             qi(x,2,1)
        elif x[0][1]==x[2][1]==1:
            qi(x,1,1)
        elif x[1][1]==x[2][1]==1:
            qi(x,0,1)
        elif x[0][2]==x[1][2]==1:
            qi(x,2,2)
        elif x[0][2]==x[2][2]==1:
            qi(x,1,2)
        elif x[1][2]==x[2][2]==1:
            qi(x,0,2)

        elif x[0][0]==x[1][1]==1:
            qi(x,2,2)
            #print(1)
        elif x[0][0]==x[2][2]==1:
            qi(x,1,1)
            #print(2)
        elif x[1][1]==x[2][2]==1:
            qi(x,0,0)
        #    print(3)
        elif x[2][0]==x[1][1]==1:
                qi(x,0,2)
        #    print(4)
        elif x[0][2]==x[1][1]==1:
            qi(x,2,0)
        #    print(5)
        elif x[0][2]==x[2][0]==1:
            qi(x,1,1)
            #print(6)

        else:
            m=0
            while m==0:
                a=random.randint(0,2)
                b=random.randint(0,2)
                if x[a][b]!=0:
                    pass
                if x[a][b]==0:
                    x[a][b]+=2
                    m+=1
    qipan=[[0,0,0],[0,0,0],[0,0,0]]
    n=0
    pygame.init()
    pygame.display.set_caption("井字棋")
    screen=pygame.display.set_mode([300,300])
    screen.fill([255,255,255])
    jing()
    while True:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
            elif event.type == pygame.MOUSEBUTTONUP:
                    if event.button==1:
                        x,y=event.pos
                        x,y=int(x/100),int(y/100)
                        if qipan[x][y]==0:
                            qipan[x][y]+=n%2+1
                            n+=1
                            drawing(qipan)
                            print(qipan)
                            wing(qipan)

                            if n<9:
                                player2(qipan)
                                n+=1
                        else:
                            print("NO")
                        drawing(qipan)
                        print(qipan)
                        wing(qipan)
        if n==9:
            n=0
            qipan=[[0,0,0],[0,0,0],[0,0,0]]
            pygame.draw.rect(screen,(255,255,255),(0,0,300,300),0)
            jing()
jingziqi()


"""
import pygame,time,random
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
def red():
    print('red wing')
    time.sleep(2)
    pygame.quit()
def hei2():
    print('black wing')
    time.sleep(2)
    pygame.quit()
def wing(x):
    if x[0][0]==x[0][1]==x[0][2]==1:
        red()
    elif x[0][0]==x[0][1]==x[0][2]==2:
        hei2()
    elif x[1][0]==x[1][1]==x[1][2]==1:
        red()
    elif x[1][0]==x[1][1]==x[1][2]==2:
        hei2()
    elif x[2][0]==x[2][1]==x[2][2]==1:
        red()
        print(3)
    elif x[2][0]==x[2][1]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][0]==x[2][0]==1:
        red()
    elif x[0][0]==x[1][0]==x[2][0]==2:
        hei2()
    elif x[0][1]==x[1][1]==x[2][1]==1:
        red()
    elif x[0][1]==x[1][1]==x[2][1]==2:
        hei2()
    elif x[0][2]==x[1][2]==x[2][2]==1:
        red()
    elif x[0][2]==x[1][2]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][1]==x[2][2]==1:
        red()
    elif x[0][0]==x[1][1]==x[2][2]==2:
        hei2()
    elif x[2][0]==x[1][1]==x[0][2]==1:
        red()
    elif x[2][0]==x[1][1]==x[0][2]==2:
        hei2()
    elif x[0][0]!=0 and x[0][1]!=0 and x[0][2]!=0 and x[1][0]!=0 and x[1][1]!=0 and x[1][2]!=0 and x[2][0]!=0 and x[2][1]!=0 and x[2][2]!=0:
        print("平局")
        time.sleep(2)
        pygame.quit()
def qi(x,a,b):
    if x[a][b]!=0:
        m=0
        while m==0:
            c=random.randint(0,2)
            d=random.randint(0,2)
            if x[c][d]!=0:
                pass
            if x[c][d]==0:
                x[c][d]+=2
                m+=1
            print(12345)
    if x[a][b]==0:
            x[a][b]+=2
def player2(x):
    if x[0][0]==x[0][1]==1:
        qi(x,0,2)
    elif x[0][0]==x[0][2]==1:
        qi(x,0,1)
    elif x[0][1]==x[0][2]==1:
        qi(x,0,0)
    elif x[1][0]==x[1][1]==1:
         qi(x,1,2)
    elif x[1][0]==x[1][2]==1:
        qi(x,1,1)
    elif x[1][1]==x[1][2]==1:
        qi(x,1,0)
    elif x[2][0]==x[2][1]==1:
        qi(x,2,2)
    elif x[2][0]==x[2][2]==1:
        qi(x,2,1)
    elif x[2][1]==x[2][2]==1:
        qi(x,2,0)

    elif x[0][0]==x[1][0]==1:
        qi(x,2,0)
    elif x[0][0]==x[2][0]==1:
        qi(x,1,0)
    elif x[1][0]==x[2][0]==1:
        qi(x,0,0)
    elif x[0][1]==x[1][1]==1:
         qi(x,2,1)
    elif x[0][1]==x[2][1]==1:
        qi(x,1,1)
    elif x[1][1]==x[2][1]==1:
        qi(x,0,1)
    elif x[0][2]==x[1][2]==1:
        qi(x,2,2)
    elif x[0][2]==x[2][2]==1:
        qi(x,1,2)
    elif x[1][2]==x[2][2]==1:
        qi(x,0,2)

    elif x[0][0]==x[1][1]==1:
        qi(x,2,2)
        #print(1)
    elif x[0][0]==x[2][2]==1:
        qi(x,1,1)
        #print(2)
    elif x[1][1]==x[2][2]==1:
        qi(x,0,0)
    #    print(3)
    elif x[2][0]==x[1][1]==1:
        qi(x,0,2)
    #    print(4)
    elif x[0][2]==x[1][1]==1:
        qi(x,2,0)
    #    print(5)
    elif x[0][2]==x[2][0]==1:
        qi(x,1,1)
        #print(6)

    else:
        m=0
        while m==0:
            a=random.randint(0,2)
            b=random.randint(0,2)
            if x[a][b]!=0:
                pass
            if x[a][b]==0:
                x[a][b]+=2
                m+=1
qipan=[[0,0,0],[0,0,0],[0,0,0]]
n=0
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
jing()
shua()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=n%2+1
                        n+=1
                        drawing(qipan)
                        print(qipan)
                        wing(qipan)

                        if n<9:
                            player2(qipan)
                            n+=1
                    else:
                        print("NO")
                    drawing(qipan)
                    print(qipan)
                    wing(qipan)



"""
"""
import pygame
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
qipan=[[0,0,0],[0,0,0],[0,0,0]]
n=0
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
jing()
shua()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=n%2+1
                        n+=1
                        print(n%2+1)
                    else:
                        print("NO")
                    drawing(qipan)

import pygame,time
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
def red():
    print('red wing')
    time.sleep(2)
    pygame.quit()
def hei2():
    print('black wing')
    time.sleep(2)
    pygame.quit()
def wing(x):
    if x[0][0]==x[0][1]==x[0][2]==1:
        red()
    elif x[0][0]==x[0][1]==x[0][2]==2:
        hei2()
    elif x[1][0]==x[1][1]==x[1][2]==1:
        red()
    elif x[1][0]==x[1][1]==x[1][2]==2:
        hei2()
    elif x[2][0]==x[2][1]==x[2][2]==1:
        red()
        print(3)
    elif x[2][0]==x[2][1]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][0]==x[2][0]==1:
        red()
    elif x[0][0]==x[1][0]==x[2][0]==2:
        hei2()
    elif x[0][1]==x[1][1]==x[2][1]==1:
        red()
    elif x[0][1]==x[1][1]==x[2][1]==2:
        hei2()
    elif x[0][2]==x[1][2]==x[2][2]==1:
        red()
    elif x[0][2]==x[1][2]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][1]==x[2][2]==1:
        red()
    elif x[0][0]==x[1][1]==x[2][2]==2:
        hei2()
    elif x[2][0]==x[1][1]==x[0][2]==1:
        red()
    elif x[2][0]==x[1][1]==x[0][2]==2:
        hei2()
    elif x[0][0]!=0 and x[0][1]!=0 and x[0][2]!=0 and x[1][0]!=0 and x[1][1]!=0 and x[1][2]!=0 and x[2][0]!=0 and x[2][1]!=0 and x[2][2]!=0:
        print("平局")
        time.sleep(2)
        pygame.quit()
qipan=[[0,0,0],[0,0,0],[0,0,0]]
n=0
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
jing()
shua()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=n%2+1
                        n+=1
                        #print(n%2+1)
                    else:
                        print("NO")
                    drawing(qipan)
                    #print(qipan)
                    wing(qipan)"""


"""
import pygame,time,random
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
def red():
    print('red wing')
    time.sleep(2)
    pygame.quit()
def hei2():
    print('black wing')
    time.sleep(2)
    pygame.quit()
def wing(x):
    if x[0][0]==x[0][1]==x[0][2]==1:
        red()
    elif x[0][0]==x[0][1]==x[0][2]==2:
        hei2()
    elif x[1][0]==x[1][1]==x[1][2]==1:
        red()
    elif x[1][0]==x[1][1]==x[1][2]==2:
        hei2()
    elif x[2][0]==x[2][1]==x[2][2]==1:
        red()
        print(3)
    elif x[2][0]==x[2][1]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][0]==x[2][0]==1:
        red()
    elif x[0][0]==x[1][0]==x[2][0]==2:
        hei2()
    elif x[0][1]==x[1][1]==x[2][1]==1:
        red()
    elif x[0][1]==x[1][1]==x[2][1]==2:
        hei2()
    elif x[0][2]==x[1][2]==x[2][2]==1:
        red()
    elif x[0][2]==x[1][2]==x[2][2]==2:
        hei2()
    elif x[0][0]==x[1][1]==x[2][2]==1:
        red()
    elif x[0][0]==x[1][1]==x[2][2]==2:
        hei2()
    elif x[2][0]==x[1][1]==x[0][2]==1:
        red()
    elif x[2][0]==x[1][1]==x[0][2]==2:
        hei2()
    elif x[0][0]!=0 and x[0][1]!=0 and x[0][2]!=0 and x[1][0]!=0 and x[1][1]!=0 and x[1][2]!=0 and x[2][0]!=0 and x[2][1]!=0 and x[2][2]!=0:
        print("平局")
        time.sleep(2)
        pygame.quit()
def qi(x,a,b):
    if x[a][b]!=0:
        m=0
        while m==0:
            c=random.randint(0,2)
            d=random.randint(0,2)
            if x[c][d]!=0:
                pass
            if x[c][d]==0:
                x[c][d]+=2
                m+=1
            print(12345)
    if x[a][b]==0:
            x[a][b]+=2
def player2(x):
    if x[0][0]==x[0][1]==1:
        qi(x,0,2)
    elif x[0][0]==x[0][2]==1:
        qi(x,0,1)
    elif x[0][1]==x[0][2]==1:
        qi(x,0,0)
    elif x[1][0]==x[1][1]==1:
         qi(x,1,2)
    elif x[1][0]==x[1][2]==1:
        qi(x,1,1)
    elif x[1][1]==x[1][2]==1:
        qi(x,1,0)
    elif x[2][0]==x[2][1]==1:
        qi(x,2,2)
    elif x[2][0]==x[2][2]==1:
        qi(x,2,1)
    elif x[2][1]==x[2][2]==1:
        qi(x,2,0)

    elif x[0][0]==x[1][0]==1:
        qi(x,2,0)
    elif x[0][0]==x[2][0]==1:
        qi(x,1,0)
    elif x[1][0]==x[2][0]==1:
        qi(x,0,0)
    elif x[0][1]==x[1][1]==1:
         qi(x,2,1)
    elif x[0][1]==x[2][1]==1:
        qi(x,1,1)
    elif x[1][1]==x[2][1]==1:
        qi(x,0,1)
    elif x[0][2]==x[1][2]==1:
        qi(x,2,2)
    elif x[0][2]==x[2][2]==1:
        qi(x,1,2)
    elif x[1][2]==x[2][2]==1:
        qi(x,0,2)

    elif x[0][0]==x[1][1]==1:
        qi(x,2,2)
        #print(1)
    elif x[0][0]==x[2][2]==1:
        qi(x,1,1)
        #print(2)
    elif x[1][1]==x[2][2]==1:
        qi(x,0,0)
    #    print(3)
    elif x[2][0]==x[1][1]==1:
        qi(x,0,2)
    #    print(4)
    elif x[0][2]==x[1][1]==1:
        qi(x,2,0)
    #    print(5)
    elif x[0][2]==x[2][0]==1:
        qi(x,1,1)
        #print(6)

    else:
        m=0
        while m==0:
            a=random.randint(0,2)
            b=random.randint(0,2)
            if x[a][b]!=0:
                pass
            if x[a][b]==0:
                x[a][b]+=2
                m+=1
qipan=[[0,0,0],[0,0,0],[0,0,0]]
n=0
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
jing()
shua()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=n%2+1
                        n+=1
                        drawing(qipan)
                        print(qipan)
                        wing(qipan)

                        if n<9:
                            player2(qipan)
                            n+=1
                    else:
                        print("NO")
                    drawing(qipan)
                    print(qipan)
                    wing(qipan)
"""

#[[ , , ]                                      ]
#[[ , , ]                                      ]
#[[ , , ]                                      ]

"""

import pygame,time
def shua():
    pygame.display.flip()
def jing():
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
def hong(a,b):
    pygame.draw.rect(screen,(255,0,0),(a*100+25,b*100+25,50,50),0) 
def hei(a,b):
    pygame.draw.rect(screen,(0,0,0),(a*100+25,b*100+25,50,50),0) 
def drawing(qipan):
    jing()
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                hong(i,j)
            if qipan[i][j]==2:
                hei(i,j)
    shua()
def red():
    print('red wing')
    time.sleep(2)
    pygame.quit()
def hei2():
    print('black wing')
    time.sleep(2)
    pygame.quit()
def wen(qipan):
    while True:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
            elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=1
                        return(qipan)
                    else:
                        print("不可以")
def xuanzhuan(z,q,a):
    if a==1:
        z[0]+=1
        if z[0]==4:
            z[0]-=4
        q1=[[q[0][2],q[1][2],q[2][2]]
            [q[0][1],q[1][1],q[2][1]]
            [q[0][0],q[1][0],q[2][0]]]
        return(z,q1)
    elif a==2:
        z[1]+=1
        if z[1]==2:
            z[1]-=2
        q1=[[q[2][2],q[1][2],q[0][2]]
            [q[2][1],q[1][1],q[0][1]]
            [q[2][0],q[1][0],q[0][0]]]
        return(z,q1)
    else:
        z[2]+=1
        if z[2]==2:
            z[2]-=2
        q1=[[q[0][0],q[1][0],q[2][0]]
            [q[0][1],q[1][1],q[2][1]]
            [q[0][2],q[1][2],q[2][2]]]
        return(z,q1)

def
qipan=[[0,0,0],[0,0,0],[0,0,0]]
zhuan=[0,0,0]
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
drawing(qipan)


# 1
qipan=wen(qipan)
drawing(qipan)
# 3
# 5
# 7
# 9

"""



































































"""
import pygame,time
def drawing(qipan):
    pygame.draw.rect(screen,(0,0,0),(0,95,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(0,195,300,10),0)
    pygame.draw.rect(screen,(0,0,0),(95,0,10,300),0)
    pygame.draw.rect(screen,(0,0,0),(195,0,10,300),0)
    for i in range(0,3):
        for j in range(0,3):
            if qipan[i][j]==0:
                pass
            if qipan[i][j]==1:
                pygame.draw.rect(screen,(255,0,0),(i*100+25,j*100+25,50,50),0) 
            if qipan[i][j]==2:
                pygame.draw.rect(screen,(0,0,0),(i*100+25,j*100+25,50,50),0) 
    pygame.display.flip()
def wen(qipan):
    while True:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
            elif event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x,y=event.pos
                    x,y=int(x/100),int(y/100)
                    if qipan[x][y]==0:
                        qipan[x][y]+=1
                        return(qipan)
                    else:
                        print("不可以")

qipan=[[0,0,0],[0,0,0],[0,0,0]]
pygame.init()
pygame.display.set_caption("井字棋")
screen=pygame.display.set_mode([300,300])
screen.fill([255,255,255])
drawing(qipan)
pan=0
# 1
qipan=wen(qipan)
if qipan[0][0]==1:

"""


drawing(qipan)
# 3
# 5
# 7
# 9











